<template>
  <div>
    <el-form :model="forms" label-width="120px" class="form-container">
      <el-row :gutter="24">
        <p class="backnumber" @click="goBack">返回</p>
        <span class="title"> 房号信息 </span>
      </el-row>
      <el-row :gutter="24">
        <el-col :span="12">
          <el-form-item label="单元名称" required>
            <el-input v-model="forms.unitname"></el-input>
          </el-form-item>
        </el-col>
        <el-col :span="12">
          <el-form-item label="幢号" required>
            <el-input v-model="forms.buildnum"></el-input>
          </el-form-item>
        </el-col>
      </el-row>
      <el-row :gutter="20">
        <el-col :span="12">
          <el-form-item label="楼层号" required>
            <el-input v-model="forms.storeynum"></el-input>
          </el-form-item>
        </el-col>
        <el-col :span="12">
          <el-form-item label="房号" required>
            <el-input v-model="forms.homenum"></el-input>
          </el-form-item>
        </el-col>
      </el-row>
      <el-row :gutter="20">
        <el-col :span="12">
          <el-form-item label="住客姓名" required>
            <el-input v-model="forms.homename"></el-input>
          </el-form-item>
        </el-col>
        <el-col :span="12">
          <el-form-item label="状态" required>
            <el-select v-model="forms.homestatus" placeholder="请选择">
              <el-option label="已入住" :value="1"></el-option>
              <el-option label="未入住" :value="2"></el-option>
            </el-select>
          </el-form-item>
        </el-col>
      </el-row>
      <el-row :gutter="20">
        <el-col :span="24">
          <el-form-item label="房屋信息">
            <el-input type="textarea" v-model="forms.homemessage"></el-input>
          </el-form-item>
        </el-col>
      </el-row>
      <el-row :gutter="20">
        <el-col :span="24">
          <el-form-item label="家庭成员">
            <el-input type="textarea" v-model="forms.homesuggestion"></el-input>
          </el-form-item>
        </el-col>
      </el-row>
    </el-form>

    <el-form
      :model="forms"
      label-width="120px"
      class="form-container"
      style="margin-top: 20px"
    >
      <el-row :gutter="24">
        <span class="title"> 智能设备 </span>
      </el-row>

      <el-row :gutter="20">
        <el-col :span="12">
          <el-form-item label="洗衣机数量" required>
            <el-input v-model="forms.washnum"></el-input>
          </el-form-item>
        </el-col>
        <el-col :span="12">
          <el-form-item label="WI-FI名称" required>
            <el-input v-model="forms.wifiname"></el-input>
          </el-form-item>
        </el-col>
      </el-row>
      <el-row :gutter="20">
        <el-col :span="12">
          <el-form-item label="空调数量" required>
            <el-input v-model="forms.airnum"></el-input>
          </el-form-item>
        </el-col>
        <el-col :span="12">
          <el-form-item label="智能设备状态" required>
            <el-select v-model="forms.smartstatus" placeholder="请选择">
              <el-option label="完好" :value="1"></el-option>
              <el-option label="待维修" :value="2"></el-option>
            </el-select>
          </el-form-item>
        </el-col>
      </el-row>
    </el-form>
    <el-form
      :model="forms"
      label-width="120px"
      class="form-container"
      style="margin-top: 20px"
    >
      <el-row :gutter="24">
        <span class="title"> 家居设备 </span>
      </el-row>

      <el-row :gutter="20">
        <el-col :span="12">
          <el-form-item label="书桌数量" required>
            <el-input v-model="forms.unitnum"></el-input>
          </el-form-item>
        </el-col>
        <el-col :span="12">
          <el-form-item label="椅子数量" required>
            <el-input v-model="forms.homechair"></el-input>
          </el-form-item>
        </el-col>
      </el-row>
      <el-row :gutter="20">
        <el-col :span="12">
          <el-form-item label="衣橱数量" required>
            <el-input v-model="forms.homeclothes" size="medium"></el-input>
          </el-form-item>
        </el-col>
        <el-col :span="12">
          <el-form-item label="家居设备状态" required>
            <el-select v-model="forms.homestatus" placeholder="请选择">
              <el-option label="完好" :value="1"></el-option>
              <el-option label="待维修" :value="2"></el-option>
            </el-select>
          </el-form-item>
        </el-col>
      </el-row>
      <el-form-item style="text-align: right; margin-top: 20px">
        <el-button type="success" @click="save">保存</el-button>
        <el-button @click="goBack" type="primary">返回</el-button>
      </el-form-item>
    </el-form>
  </div>
</template>

<script>
export default {
  data() {
    return {
      forms: {},
    };
  },
  created() {
    this.getDate();
  },
  methods: {
    // 默认调数据
    getDate() {
      const id = this.$route.query.id;
      this.$Axios({
        url: "/house/getDetailId",
        method: "get",
        data: {
          id: id,
        },
        success: (result) => {
          this.form = result.data;
          setTimeout(() => {
            this.loading = false;
          }, 200);
        },
        success: (result) => {
          this.forms = result[0];
          //   this.form = result.data;
          console.log(this.forms);
          setTimeout(() => {
            this.loading = false;
          }, 200);
        },
      });
    },

    save() {
      this.$confirm("保存？", "提示", {
        type: "warning",
      })
        .then(() => {
          const id = this.$route.query.id;
          this.$Axios({
            url: "/house/updatenumList",
            method: "POST",
            data: {
              id: id,
              unitname: this.forms.unitname,
              buildnum: this.forms.buildnum,
              storeynum: this.forms.storeynum,
              homenum: this.forms.homenum,
              homename: this.forms.homename,
              homestatus: this.forms.homestatus,
              homemessage: this.forms.homemessage,
              homemessage: this.forms.homesuggestion,
              airnum: this.forms.airnum,
              wifiname: this.forms.wifiname,
              washnum: this.forms.washnum,
              smartstatus: this.forms.smartstatus,
              homedesk: this.forms.homedesk,
              homechair: this.forms.homechair,
              homeclothes: this.forms.homeclothes,
              familystatus: this.forms.familystatus,
              h_id: id,
              homeaddress: this.forms.homeaddress,
            },
            success: (result) => {
                this.$message({
                  type: "success",
                  message: "保存成功",
                });
                this.$router.push({
                  path: "/house/number",
                });
            },
            error: (reason) => {
              alert("保存失败" + reason);
            },
          });
        })
        .catch(() => {
          this.$message({
            type: "info",
            message: "已取消",
          });
        });

      // 在这里添加保存逻辑
    },
    goBack() {
      console.log("返回");
      this.$router.push({
        path: "/house/number",
      });
      // 在这里添加返回逻辑
    },
  },
};
</script>

<style>
.form-container {
  max-width: 800px;
  margin: 0 auto;
}
.title {
  font-size: 18px;
  font-weight: bold;
  margin-bottom: 20px;
  border-left: 5px solid #409eff;
  padding-left: 10px;
  display: block;
  line-height: 34px;
}
.backnumber {
  line-height: 34px;
  color: #409eff;
  cursor: pointer;
}
</style>